/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package uit.qlks.controller.phong;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.sql.rowset.WebRowSet;
import uit.ejb.bo.phong.PhongBORemote;
import uit.ejb.bo.phong.PhongBORemoteHome;
import uit.ejb.dto.PhongDTO;

/**
 *
 * @author Restart
 */
public class PhongController {

    private static Context ctx;
    private static PhongBORemoteHome phome;
    private static PhongBORemote p;
    public PhongController(){

    }
    public static void Register(){
        try{
            ctx = new InitialContext();
            Object obj = ctx.lookup("ejb/PhongBO");
            phome = (PhongBORemoteHome) PortableRemoteObject.narrow(obj, PhongBORemoteHome.class);
            p=phome.create();
        }
        catch(Exception e){
        }
    }

    public static boolean kiemTraTrung(PhongDTO phong) {
        try{
            Register();
            return p.kiemTraTrung(phong);
        }catch(Exception e){
            e.getMessage();
            return false;
        }
    }

    public static boolean phong_Insert(PhongDTO phong) {
        try{
            Register();
            return p.phong_Insert(phong);
        }catch(Exception e){
            e.getMessage();
            return false;
        }
    }

    public static boolean phong_Update(PhongDTO phong) {
        try{
            Register();
            return p.phong_Update(phong);
        }catch(Exception e){
            e.getMessage();
            return false;
        }
    }

    public static boolean phong_Delete(String id) {
        try{
            Register();
            return p.phong_Delete(id);
        }catch(Exception e){
            e.getMessage();
            return false;
        }
    }

    public static WebRowSet phong_GetByAll() {
        try{
            Register();
            return p.phong_GetByAll();
        }catch(Exception e){
            e.getMessage();
            return null;
        }
    }

    public static WebRowSet phong_GetById(String id) {
        try{
            Register();
            return p.phong_GetById(id);
        }catch(Exception e){
            e.getMessage();
            return null;
        }
    }

    public static WebRowSet phong_GetByTop(String top, String where, String order) {
        try{
            Register();
            return p.phong_GetByTop(top, where, order);
        }catch(Exception e){
            e.getMessage();
            return null;
        }
    }

    public static void phong_UpdateStatus(String id, String status) {
        try{
            Register();
            p.phong_UpdateStatus(id, status);
        }catch(Exception e){
            e.getMessage();
        }
    }
}
